<?php
class SettingSaveVipAction extends AdminAction
{
	public function __construct()
	{
		parent::__construct();
		$this->responseType = 'json';
	}
	
	protected function afterConstruct()
	{
		$this->parseDtds('vip','setting');
	}
	
	public function execute()
	{
		$key = str_replace('"', '', $this->context->post('vipkey'));
		$secret = str_replace('"', '', $this->context->post('vipsecret'));
		
		$confFile	= substr(dirname(__FILE__), 0, strrpos(__FILE__, "app")).'conf/conf.php';
		
		$content = file_get_contents($confFile);
		$content = preg_replace('~\$config\["api"\]\["key"\]\s+=\s+".*?"~is', '$config["api"]["key"] = "'.$key.'"', $content);
		$content = preg_replace('~\$config\["api"\]\["secret"\]\s+=\s+".*?"~is', '$config["api"]["secret"] = "'.$secret.'"', $content);
		
		$ret = file_put_contents($confFile, $content);
		if($ret)
		{
			$this->code = 200;
		}
		else
		{
			$this->code = 500;
		}
	}
}
